using Microsoft.AspNetCore.Mvc;
using ZR.Model.FacManage.Dto;
using ZR.Model.FacManage;
using ZR.Service.FacManage.IFacManageService;
using ZR.Admin.WebApi.Filters;
using ZR.Service.FacManage;

//创建时间：2025-04-20
namespace ZR.Admin.WebApi.Controllers.FacManage
{
    /// <summary>
    /// 库区信息
    /// </summary>
    [Verify]
    [Route("FacManage/FacWhse")]
    public class FacWhseController : BaseController
    {
        /// <summary>
        /// 库区信息接口
        /// </summary>
        private readonly IFacWhseService _FacWhseService;

        public FacWhseController(IFacWhseService FacWhseService)
        {
            _FacWhseService = FacWhseService;
        }

        /// <summary>
        /// 查询库区信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "fac:whse:list")]
        public IActionResult PageFacWhse([FromQuery] FacWhseQueryDto parm)
        {
            var response = _FacWhseService.GetPageList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 获取库区树信息
        /// </summary>
        /// <param name="disabledFactory">禁用工厂选择</param>
        /// <returns></returns>
        [HttpGet("treeList")]
        [ActionPermissionFilter(Permission = "fac:workshop:list")]
        public IActionResult TreeFacWhse(bool disabledFactory)
        {
            var response = _FacWhseService.GetTreeList(disabledFactory);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询库区信息详情
        /// </summary>
        /// <param name="WhseId"></param>
        /// <returns></returns>
        [HttpGet("{WhseId}")]
        [ActionPermissionFilter(Permission = "fac:whse:query")]
        public IActionResult GetFacWhse(string WhseId)
        {
            var response = _FacWhseService.GetInfo(WhseId);
            
            var info = response.Adapt<FacWhseDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加库区信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "fac:whse:add")]
        [Log(Title = "库区信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddFacWhse([FromBody] FacWhseDto parm)
        {
            var modal = parm.Adapt<FacWhse>().ToCreate(HttpContext);

            var response = _FacWhseService.AddFacWhse(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新库区信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "fac:whse:edit")]
        [Log(Title = "库区信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateFacWhse([FromBody] FacWhseDto parm)
        {
            var modal = parm.Adapt<FacWhse>().ToUpdate(HttpContext);
            var response = _FacWhseService.UpdateFacWhse(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除库区信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "fac:whse:delete")]
        [Log(Title = "库区信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteFacWhse([FromBody] string[] ids)
        {
            var response = _FacWhseService.DeleteFacWhse(ids);
            return ToResponse(response);
        }

    }
}